//
//  SFAttributeView.h
//  CoreText进阶封装
//
//  Created by xueshan1 on 2019/2/18.
//  Copyright © 2019 baiqiang. All rights reserved.
//
/*
 功能:
 1.富文本
 2.可点击链接
 3.图文混排
 
 使用范例:
    NSString *str = @"的框架拉黑老虎迪佛爱好都是;奥房间啊搜狐奥;东四环发;哦is的狐狸哦;待会;了;奥房间啊搜狐奥;东四环发;哦is的狐狸哦;待会;了;奥房间啊搜狐奥;东四环发;哦is的狐狸哦;待会;了对方好句;大富豪发;哦is的狐狸哦;待会;了对方好句;大富豪发;哦is的狐狸哦;待会;了对方好句;大富豪v;的接口海底捞;开收据";
 
    SFAttributeView *attributeView = [[SFAttributeView alloc]initWithFrame:CGRectMake(10, 200, 300, 100) string:str font:nil textColor:[UIColor blackColor] ];//fitRealHeight:YES numberOfLines:1 truncationToken:@"展开>>"
    attributeView.delegate = self;
    attributeView.backgroundColor = [UIColor whiteColor];
    attributeView.clickTruncationBlock = ^(SFAttributeView * _Nonnull view) {
        view.numberOfLines = 0;
    };
     
    UIImage *image = [UIImage imageNamed:@"test1"];
    [attributeView insertImageWithLocation:5 imageName:@"test1" imageSize:image.size canClick:YES];
 
    [attributeView addHighlightStringRange:NSMakeRange(6, 19) highlightColor:[UIColor cyanColor] canClick:YES showUnderLine:NO linkData:@{@"ame":@"打瞌睡句话"}];
    [self.view addSubview:attributeView];
 
 
 
 */
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN
@class SFAttributeView;
@protocol SFAttributeViewDelegate <NSObject>

- (void)attributeView:(SFAttributeView *)view clickLinkWithLinkData:(NSDictionary *)linkData;
- (void)attributeView:(SFAttributeView *)view clickImageWithImageName:(NSString *)imageName;

@end


@interface SFAttributeView : UIView

@property(nonatomic,weak)id <SFAttributeViewDelegate>delegate;
@property(nonatomic,assign) BOOL fitRealHeight;
@property(nonatomic,assign) NSInteger numberOfLines;
@property(nonatomic,copy) void(^clickTruncationBlock)(SFAttributeView *view);//查看更多
/**
 init
 高度会自适应
 fitRealHeight  :default 自适应高度
 truncationToken: "...更多"
 */
- (instancetype)initWithFrame:(CGRect)frame string:(NSString *)string font:(UIFont *)font textColor:(UIColor *)textColor;
- (instancetype)initWithFrame:(CGRect)frame string:(NSString *)string font:(UIFont *)font textColor:(UIColor *)textColor fitRealHeight:(BOOL)fitRealHeight;
- (instancetype)initWithFrame:(CGRect)frame string:(NSString *)string font:(UIFont *)font textColor:(UIColor *)textColor fitRealHeight:(BOOL)fitRealHeight numberOfLines:(NSInteger)numberOfLines truncationToken:(NSString *_Nullable)truncationToken;


/**
 可点击富文本
 
 @param highlightRange 高亮范围
 @param highlightColor 高亮颜色
 @param canClick 是否可点击
 @param showUnderLine 是否带下划线
 @param linkData 高亮的数据  主要键:使用 @{"linkKey":@""}

 */
- (void)addHighlightStringRange:(NSRange)highlightRange highlightColor:(UIColor *)highlightColor canClick:(BOOL)canClick showUnderLine:(BOOL)showUnderLine  linkData:(NSDictionary *_Nullable)linkData; 
- (void)addHighlightStringRange:(NSRange)highlightRange highlightColor:(UIColor *)highlightColor;
- (void)addHighlightStringRange:(NSRange)highlightRange highlightColor:(UIColor *)highlightColor canClick:(BOOL)canClick showUnderLine:(BOOL)showUnderLine;


/**
 图文混排 - 插入图片
 */
- (void)appendImageName:(NSString *)imageName imageSize:(CGSize)imageSize canClick:(BOOL)canClick;
- (void)insertImageWithLocation:(NSUInteger)location imageName:(NSString *)imageName imageSize:(CGSize)imageSize canClick:(BOOL)canClick;


/**
 自定义 view
 */
- (void)insertCustomView:(UIView *)customView inLocation:(NSUInteger)location;


@end

NS_ASSUME_NONNULL_END
